package com.bibrApp.difu.actvity.huankuan_mvp;

import android.content.Context;
import android.util.Log;

import com.bibrApp.difu.DfApp;
import com.bibrApp.difu.Response.FBInfoResBody;
import com.bibrApp.difu.Response.OrderDetailResBody;
import com.bibrApp.difu.Response.RePayInfoResBody;
import com.bibrApp.difu.actvity.jiechu_mvp.IJiechuView;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.utils.AppManager;
import com.bibrApp.difu.utils.EncryptUtils;
import com.google.gson.Gson;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class HuankuanPresenter extends BasePresenter<IHuankuanView> {
    public HuankuanPresenter(Context context, IHuankuanView iView) {
        super(context, iView);
    }

    public void getData(String orderNo) {
        RetrofitNet.getInstance()
                .getApi()
                .getRePayInfo(EncryptUtils.encryptNewType(orderNo))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new BaseObserver<Object>(context) {

                    @Override
                    protected void onSuccess(Object value) {
                        if(value != null){
                            String jsonStr = EncryptUtils.objectToJson(value);
                            RePayInfoResBody orderDetailResBody = new Gson().fromJson(jsonStr, RePayInfoResBody.class);
                            iView.successOfGetRepayInfo(orderDetailResBody);
                        }
                    }

                    @Override
                    protected void onFialure(int code, String msg) {
                        super.onFialure(code, msg);
                    }
                });
    }



}
